import React from 'react';
import { connect } from 'dva';
import _ from 'lodash';
/*
 import styles from './index.less';
 */
import jump from '../../../utils/jump';
import { ChildWrap, Content } from '../../../components/layout/';
import PatientLeft from './patient-left';
import PatientRight from './patient-right';

function Patient({ dispatch, patient }) {
    const { current: cur, menu, tableShow } = patient;
    const back = (e) => {
        e.preventDefault();
        jump(dispatch)('home/check');
    };
    const changeItem = (key) => {
        const current = _.find(menu, ['value', key]);
        if (key !== cur.value) {
            dispatch({
                type: 'patient/setState',
                payload: {
                    current,
                },
            });
        }
    };
    const data = patient[cur.value];
    const props = {
        left: (
            <ChildWrap
                iconName="left"
                content="病例"
                onLeftClick={back}
                padding="30px 0"
            >
                <PatientLeft
                    patient={patient}
                    changeItem={changeItem}
                />
            </ChildWrap>
        ),
        right: (
            <ChildWrap
                iconName={null}
                content={cur.label}
            >
                <PatientRight
                    data={data}
                    UIType={cur.UIType}
                    tableShow={tableShow}
                />
            </ChildWrap>
        ),
    };
    return (
        <Content
            {...props}
        />
    );
}
/*
 * 需要引用的model，解构传入mapStateToProps方法，并返回出来；
 * 组建的props中将会获取model数据
 * */
function mapStateToProps({ patient }) {
    return { patient };
}

export default connect(mapStateToProps)(Patient);
